import useUserStore from "@/store/userStore";
import { faker } from "@faker-js/faker";

import { BasicStatus, PermissionType } from "#/enum";
/**
 * Organization data mock
 */
export const ORG_LIST = [
	{
		id: "1",
		name: "East China Branch",
		status: "enable",
		desc: faker.lorem.words(),
		order: 1,
		children: [
			{
				id: "1-1",
				name: "R&D Department",
				status: "disable",
				desc: "",
				order: 1,
			},
			{
				id: "1-2",
				name: "Marketing Department",
				status: "enable",
				desc: "",
				order: 2,
			},
			{
				id: "1-3",
				name: "Finance Department",
				status: "enable",
				desc: "",
				order: 3,
			},
		],
	},
	{
		id: "2",
		name: "South China Branch",
		status: "enable",
		desc: faker.lorem.words(),
		order: 2,
		children: [
			{
				id: "2-1",
				name: "R&D Department",
				status: "disable",
				desc: "",
				order: 1,
			},
			{
				id: "2-2",
				name: "Marketing Department",
				status: "enable",
				desc: "",
				order: 2,
			},
			{
				id: "2-3",
				name: "Finance Department",
				status: "enable",
				desc: "",
				order: 3,
			},
		],
	},
];

/**
 * User permission mock
 */
const DASHBOARD_PERMISSION = {
	id: "9100714781927703",
	parentId: "",
	label: "sys.menu.dashboard",
	name: "Dashboard",
	icon: "ic-analysis",
	type: PermissionType.CATALOGUE,
	route: "dashboard",
	order: 1,
	children: [
		{
			id: "8426999229400979",
			parentId: "9100714781927703",
			label: "sys.menu.workbench",
			name: "Workbench",
			type: PermissionType.MENU,
			route: "workbench",
			component: "/dashboard/analysis/index.tsx",
		},
	],
};

const TASK_PERMISSION = {
	id: "9100714781927704",
	parentId: "",
	label: "sys.menu.task",
	name: "Task",
	icon: "fluent:task-list-square-16-filled",
	type: PermissionType.CATALOGUE,
	route: "task",
	status: BasicStatus.ENABLE,
	children: [
		{
			id: "9100714781927705",
			parentId: "9100714781927704",
			label: "sys.menu.task.list",
			name: "Task List",
			type: PermissionType.MENU,
			route: "task/list",
			status: BasicStatus.ENABLE,
			children: [],
			component: "/task/list/index.tsx",
		},
		{
			id: "9100714781927706",
			parentId: "9100714781927704",
			label: "sys.menu.task.category",
			name: "Task Category",
			type: PermissionType.MENU,
			route: "task/category",
			status: BasicStatus.ENABLE,
			children: [],
			component: "/task/category/index.tsx",
		},
	],
};

const TASK_SUMMIT_PERMISSION = {
	id: "910071478192171704",
	parentId: "",
	icon: "fluent:task-list-square-16-filled",
	label: "任务提交记录",
	name: "Task Submit",
	type: PermissionType.MENU,
	route: "task/submit",
	status: BasicStatus.ENABLE,
	children: [],
	component: "/task/submit/index.tsx",
};

const ATTACHMENT_PERMISSION = {
	id: "123",
	parentId: "",
	label: "文件管理",
	name: "Attachment",
	icon: "fluent:task-list-square-16-filled",
	type: PermissionType.CATALOGUE,
	route: "attachment",
	status: BasicStatus.ENABLE,
	children: [
		{
			id: "12333",
			parentId: "123",
			label: "文件列表",
			name: "Attachment List",
			type: PermissionType.MENU,
			route: "list",
			status: BasicStatus.ENABLE,
			children: [],
			component: "/attachment/index.tsx",
		},
		{
			id: "1234",
			parentId: "123",
			label: "文件分类",
			name: "Attachment Category",
			type: PermissionType.MENU,
			route: "category",
			status: BasicStatus.ENABLE,
			children: [],
			component: "/attachment/category.tsx",
		},
	],
};

const USER_PERMISSION = {
	id: "9100714781927704",
	parentId: "",
	label: "用户列表",
	name: "User",
	icon: "solar:user-bold-duotone",
	type: PermissionType.MENU,
	route: "user",
	component: "/user/index.tsx",
};

const PROJECT_PERMISSION = {
	id: "9100714781927704",
	parentId: "",
	label: "项目列表",
	name: "User",
	icon: "eos-icons:project-outlined",
	type: PermissionType.MENU,
	route: "project",
	component: "/project/list/index.tsx",
};

const NOTICE_PERMISSION = {
	id: "9100714781927704",
	parentId: "",
	label: "通知列表",
	name: "Notice",
	icon: "eos-icons:project-outlined",
	type: PermissionType.MENU,
	route: "notice",
	component: "/notice/list/index.tsx",
};

const KNOWLEDGE_PERMISSION = {
	id: "9100714781927704",
	parentId: "",
	label: "知识管理",
	name: "Knowledge",
	icon: "hugeicons:knowledge-02",
	type: PermissionType.MENU,
	route: "knowledge",
	component: "/knowledge/list/index.tsx",
};

const SETTING_PERMISSION = {
	id: "9100714781927704",
	parentId: "",
	label: "设置",
	name: "Setting",
	icon: "weui:setting-filled",
	type: PermissionType.MENU,
	route: "setting",
	component: "/setting/index.tsx",
};

const MANAGEMENT_PERMISSION = {
	id: "0901673425580518",
	parentId: "",
	label: "sys.menu.management",
	name: "Management",
	icon: "ic-management",
	type: PermissionType.CATALOGUE,
	route: "management",
	order: 2,
	children: [
		// {
		// 	id: "2781684678535711",
		// 	parentId: "0901673425580518",
		// 	label: "sys.menu.user.index",
		// 	name: "User",
		// 	type: PermissionType.CATALOGUE,
		// 	route: "user",
		// 	children: [
		// 		{
		// 			id: "4754063958766648",
		// 			parentId: "2781684678535711",
		// 			label: "sys.menu.user.profile",
		// 			name: "Profile",
		// 			type: PermissionType.MENU,
		// 			route: "profile",
		// 			component: "/management/user/account/index.tsx",
		// 		},
		// 	],
		// },
		{
			id: "0249937641030250",
			parentId: "0901673425580518",
			label: "sys.menu.system.index",
			name: "System",
			type: PermissionType.CATALOGUE,
			route: "system",
			children: [
				// {
				// 	id: "1985890042972842",
				// 	parentId: "0249937641030250",
				// 	label: "sys.menu.system.organization",
				// 	name: "Organization",
				// 	type: PermissionType.MENU,
				// 	route: "organization",
				// 	component: "/management/system/organization/index.tsx",
				// },
				// {
				// 	id: "4359580910369984",
				// 	parentId: "0249937641030250",
				// 	label: "sys.menu.system.permission",
				// 	name: "Permission",
				// 	type: PermissionType.MENU,
				// 	route: "permission",
				// 	component: "/management/system/permission/index.tsx",
				// },
				// {
				// 	id: "1689241785490759",
				// 	parentId: "0249937641030250",
				// 	label: "sys.menu.system.role",
				// 	name: "Role",
				// 	type: PermissionType.MENU,
				// 	route: "role",
				// 	component: "/management/system/role/index.tsx",
				// },
				{
					id: "0157880245365433",
					parentId: "0249937641030250",
					label: "审核员",
					name: "User",
					type: PermissionType.MENU,
					route: "user",
					component: "/management/system/user/index.tsx",
				},
				{
					id: "0157880245365434",
					parentId: "0249937641030250",
					label: "sys.menu.system.user_detail",
					name: "User Detail",
					type: PermissionType.MENU,
					route: "user/:id",
					component: "/management/system/user/detail.tsx",
					hide: true,
				},
			],
		},
	],
};

const ERRORS_PERMISSION = {
	id: "9406067785553476",
	parentId: "",
	label: "sys.menu.error.index",
	name: "Error",
	icon: "bxs:error-alt",
	type: PermissionType.CATALOGUE,
	route: "error",
	order: 6,
	children: [
		{
			id: "8557056851997154",
			parentId: "9406067785553476",
			label: "sys.menu.error.403",
			name: "403",
			type: PermissionType.MENU,
			route: "403",
			component: "/sys/error/Page403.tsx",
		},
		{
			id: "5095669208159005",
			parentId: "9406067785553476",
			label: "sys.menu.error.404",
			name: "404",
			type: PermissionType.MENU,
			route: "404",
			component: "/sys/error/Page404.tsx",
		},
		{
			id: "0225992135973772",
			parentId: "9406067785553476",
			label: "sys.menu.error.500",
			name: "500",
			type: PermissionType.MENU,
			route: "500",
			component: "/sys/error/Page500.tsx",
		},
	],
};

const OTHERS_PERMISSION = [
	{
		id: "3981225257359246",
		parentId: "",
		label: "sys.menu.calendar",
		name: "Calendar",
		icon: "solar:calendar-bold-duotone",
		type: PermissionType.MENU,
		route: "calendar",
		component: "/sys/others/calendar/index.tsx",
	},
	{
		id: "3513985683886393",
		parentId: "",
		label: "sys.menu.kanban",
		name: "kanban",
		icon: "solar:clipboard-bold-duotone",
		type: PermissionType.MENU,
		route: "kanban",
		component: "/sys/others/kanban/index.tsx",
	},
	{
		id: "5455837930804461",
		parentId: "",
		label: "sys.menu.disabled",
		name: "Disabled",
		icon: "ic_disabled",
		type: PermissionType.MENU,
		route: "disabled",
		status: BasicStatus.DISABLE,
		component: "/sys/others/calendar/index.tsx",
	},
	{
		id: "7728048658221587",
		parentId: "",
		label: "sys.menu.label",
		name: "Label",
		icon: "ic_label",
		type: PermissionType.MENU,
		route: "label",
		newFeature: true,
		component: "/sys/others/blank.tsx",
	},
	{
		id: "5733704222120995",
		parentId: "",
		label: "sys.menu.frame",
		name: "Frame",
		icon: "ic_external",
		type: PermissionType.CATALOGUE,
		route: "frame",
		children: [
			{
				id: "9884486809510480",
				parentId: "5733704222120995",
				label: "sys.menu.external_link",
				name: "External Link",
				type: PermissionType.MENU,
				route: "external_link",
				hideTab: true,
				component: "/sys/others/iframe/external-link.tsx",
				frameSrc: "https://ant.design/",
			},
			{
				id: "9299640886731819",
				parentId: "5733704222120995",
				label: "sys.menu.iframe",
				name: "Iframe",
				type: PermissionType.MENU,
				route: "frame",
				component: "/sys/others/iframe/index.tsx",
				frameSrc: "https://ant.design/",
			},
		],
	},
	{
		id: "0941594969900756",
		parentId: "",
		label: "sys.menu.blank",
		name: "Disabled",
		icon: "ic_blank",
		type: PermissionType.MENU,
		route: "blank",
		component: "/sys/others/blank.tsx",
	},
];

export const PERMISSION_LIST = [
	DASHBOARD_PERMISSION,
	TASK_PERMISSION,
	TASK_SUMMIT_PERMISSION,
	MANAGEMENT_PERMISSION,
	USER_PERMISSION,
	PROJECT_PERMISSION,
	NOTICE_PERMISSION,
	KNOWLEDGE_PERMISSION,
	// ATTACHMENT_PERMISSION,
	SETTING_PERMISSION,
	// ERRORS_PERMISSION,
	// ...OTHERS_PERMISSION,
];

export const PERMISSION_LIST_WITH_CHILDREN = [
	DASHBOARD_PERMISSION,
	TASK_SUMMIT_PERMISSION,
];
/**
 * User role mock
 */
const ADMIN_ROLE = {
	id: "4281707933534332",
	name: "Admin",
	label: "admin",
	status: BasicStatus.ENABLE,
	order: 1,
	desc: "Super Admin",
	permission: PERMISSION_LIST,
};
const TEST_ROLE = {
	id: "9931665660771476",
	name: "Test",
	label: "test",
	status: BasicStatus.ENABLE,
	order: 2,
	desc: "test",
	permission: [DASHBOARD_PERMISSION],
};
export const ROLE_LIST = [ADMIN_ROLE, TEST_ROLE];

/**
 * User data mock
 */
export const DEFAULT_USER = {
	id: "b34719e1-ce46-457e-9575-99505ecee828",
	username: "admin",
	email: faker.internet.email(),
	avatar: faker.image.avatarGitHub(),
	createdAt: faker.date.anytime(),
	updatedAt: faker.date.recent(),
	password: "demo1234",
	role: ADMIN_ROLE,
	permissions: ADMIN_ROLE.permission,
};
export const TEST_USER = {
	id: "efaa20ea-4dc5-47ee-a200-8a899be29494",
	username: "test",
	password: "demo1234",
	email: faker.internet.email(),
	avatar: faker.image.avatarGitHub(),
	createdAt: faker.date.anytime(),
	updatedAt: faker.date.recent(),
	role: TEST_ROLE,
	permissions: TEST_ROLE.permission,
};
export const USER_LIST = [DEFAULT_USER, TEST_USER];

// * Hot update, updating user permissions, only effective in the development environment
if (import.meta.hot) {
	import.meta.hot.accept((newModule) => {
		if (!newModule) return;

		const { DEFAULT_USER, TEST_USER, PERMISSION_LIST } = newModule;

		const {
			userInfo,
			actions: { setUserInfo },
		} = useUserStore.getState();

		if (!userInfo?.username) return;

		const newUserInfo =
			userInfo.username === DEFAULT_USER.username ? DEFAULT_USER : TEST_USER;

		setUserInfo(newUserInfo);

		console.log("[HMR] User permissions updated:", {
			username: newUserInfo.username,
			permissions: newUserInfo.permissions,
		});
	});
}
